#include "../include/data_global.h"

extern unsigned char dev_led_mask;  //LED操作掩码
extern int dev_led_fd;              

extern pthread_mutex_t mutex_led;   //互斥锁

extern pthread_cond_t cond_led;     //LED控制模块被唤醒条件变量

void *pthread_led (void *arg)
{
	unsigned char led_mask;
	if ((dev_led_fd = open (DEV_LED, O_RDWR | O_NONBLOCK)) < 0 )
	{
		printf ("Cann't open file /dev/led\n");
		exit (-1);
	}
    while(1)
    {

        pthread_mutex_lock (&mutex_led);
        pthread_cond_wait (&cond_led, &mutex_led);
        led_mask = dev_led_mask;
        pthread_mutex_unlock (&mutex_led);

        switch (led_mask)
        {
            case FS4412_LED2_OFF:
                {
                    ioctl (dev_led_fd, FS4412_LED2_OFF);
                    break;
                }
            case FS4412_LED2_ON:
                {
                    ioctl (dev_led_fd, FS4412_LED2_ON);
                    break;
                }
            case FS4412_LED3_OFF:
                {
                    ioctl (dev_led_fd, FS4412_LED3_OFF);
                    break;
                }
            case FS4412_LED3_ON:
                {
                    ioctl (dev_led_fd, FS4412_LED3_ON);
                    break;
                }
            default :break;
        }
    }

}

